I am trying to add and AND condition to my entity framework where clause, but the way I am doing it is not working. Can anyone show me how to do this the correct way please? Before adding the AND condition, the code worked fine.
Dim myRecipeStepsHistory = myContext.RefineRecipeStep.Where("it.Recipe_Id=" & strRecipeId And "it.IngredientItemNumber=" & strIngredientNumber).FirstOrDefault()
The error I get reads as:
Conversion from string "it.Recipe_Id=11" to type 'Long' is not valid.
Thank you very much.
Anonymous User
19-Jan-2015I would try to use the built in linq if you can. It will check your values at compile time for you and you won't get nasty surprises at run time. You can use magic-strings of course but why not use one of the best features of of an ORM? Imagine updating a tables field type, the compiler will automatically let you know every place you need to update your code. Instead of having forgetting about one and then having it crash here and there.
If you're querying a single table, often it's easier to put the 'wheres' inside the FirstOrDefault();
You may have to cast your values so it matches the correct data type for Recipe_Id and IngredientItemNumber.